package view;

import java.sql.SQLException;

import com.example.pruebapfi.R;

import DB.DatabaseHelper;
import android.support.v4.app.Fragment;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.Button;

public class MainActivityOptionsFragment extends Fragment {
	
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
	        View v = inflater.inflate(R.layout.activity_main_activity_options, container, false);
	        final Activity activity=getActivity();
            Button buttonBuscarAlimentoCategoria= (Button) v.findViewById( R.id.ButtonBuscarAlimentoCategoria);
            Button buttonModRegimen= (Button) v.findViewById( R.id.ButtonModRegimen);
            Button buttonComidaDia= (Button) v.findViewById( R.id.ButtonComidaDia);
            Button buttonInforme= (Button) v.findViewById( R.id.ButtonInforme);
            Button buttonIngesta= (Button) v.findViewById( R.id.ButtonIngesta);
            Button buttonIngestaLiquido= (Button) v.findViewById( R.id.ButtonIngestaLiquido);
            Button buttonMostrarAlimento= (Button) v.findViewById( R.id.ButtonMostrarAlimento);
            Button buttonUltimaAlimento= (Button) v.findViewById( R.id.ButtonUltimoAlimento);
            Button buttonVerConsejos= (Button) v.findViewById( R.id.ButtonConsejos);
            Button buttonVerNotificaciones= (Button) v.findViewById( R.id.ButtonNotificaciones);
            
            buttonVerConsejos.setOnClickListener(new OnClickListener() {
			    			public void onClick(View v) {	
			    				Intent intent= new Intent(activity.getApplicationContext(),ListarConsejos.class);
			    				startActivity(intent);
			    			}
            });
			 
            buttonVerNotificaciones.setOnClickListener(new OnClickListener() {
					public void onClick(View v) {	
						Intent intent= new Intent(activity.getApplicationContext(),ListarNotificaciones.class);
						startActivity(intent);
					}
			});
            
            buttonBuscarAlimentoCategoria.setOnClickListener(new OnClickListener() {
    			public void onClick(View v) {	
    				Intent intent= new Intent(activity.getApplicationContext(),ListarCategorias.class);
    				startActivity(intent);
    			}
    		});
            
            buttonModRegimen.setOnClickListener(new OnClickListener() {
    			public void onClick(View v) {
    				Intent intent= new Intent(activity.getApplicationContext(),IngresarValoresDieta.class);
    				startActivity(intent);	
    			}
    		});
            
            buttonComidaDia.setOnClickListener(new OnClickListener() {
    			public void onClick(View v) {
    				Intent intent= new Intent(activity.getApplicationContext(),VerConsumo.class);
    				intent.putExtra("tipo", "consulta_consumo_ultimo");
    				startActivity(intent);	
    			}
    		});
            
            buttonInforme.setOnClickListener(new OnClickListener() {
    			public void onClick(View v) {
    				Intent intent= new Intent(activity.getApplicationContext(),EnviarInformeMail.class);
    				startActivity(intent);	
    			}
    		});
            
            buttonMostrarAlimento.setOnClickListener(new OnClickListener() {
    			@Override
    			public void onClick(View v) {
    				Intent intent= new Intent(activity.getApplicationContext(),ListarAlimentos.class);
    				intent.putExtra("tipo", "todos");
    				startActivity(intent);
    			}
    		});
            
            buttonIngesta.setOnClickListener(new OnClickListener() {
    			@Override
    			public void onClick(View v) {
    				DatabaseHelper db= new DatabaseHelper(activity.getApplicationContext());
    				try {
    					//Verifica que exista un Regimen Alimenticio creado o lo manda a crear uno
    					if(db.getRegimenAlimenticioDao().queryBuilder().queryForFirst() == null){
    						Intent intent= new Intent(activity.getApplicationContext(),IngresarValoresDieta.class);
    						startActivity(intent);
    					}else{
    						Intent intent= new Intent(activity.getApplicationContext(),ListarAlimentos.class);
    						intent.putExtra("tipo", "ingesta");
    						startActivity(intent);
    					}
    				} catch (SQLException e) {
    					e.printStackTrace();
    				}	
    			}
    		});
            
            buttonIngestaLiquido.setOnClickListener(new OnClickListener() {
    			@Override
    			public void onClick(View v) {
    				DatabaseHelper db= new DatabaseHelper(activity.getApplicationContext());
    				try {
    					//Verifica que exista un Regimen Alimenticio creado o lo manda a crear uno
    					if(db.getRegimenAlimenticioDao().queryBuilder().queryForFirst() == null){
    						Intent intent= new Intent(activity.getApplicationContext(),IngresarValoresDieta.class);
    						startActivity(intent);
    					}else{
    						Intent intent= new Intent(activity.getApplicationContext(),IngresarLiquido.class);
    						startActivity(intent);
    					}
    				} catch (SQLException e) {
    					e.printStackTrace();
    				}	
    			}
    		});
            
            buttonUltimaAlimento.setOnClickListener(new OnClickListener() {
    			@Override
    			public void onClick(View v) {
    				Intent intent= new Intent(activity.getApplicationContext(),BusquedaConsumos.class);
    		
    				startActivity(intent);
    			}
    		});
        return v;
    }

    public static MainActivityOptionsFragment newInstance() {

    	MainActivityOptionsFragment f = new MainActivityOptionsFragment();
        Bundle b = new Bundle();
        f.setArguments(b);
        return f;
    }

}
